# -*- coding: utf-8 -*-
'''
author:Cooper
date:2012.5.7

物流API
see:http://open.taobao.com/doc/api_cat_detail.htm?cat_id=7&category_id=102

taobao.areas.get 查询地址区域
taobao.delivery.template.get 获取用户指定运费模板信息
taobao.delivery.templates.get 获取用户下所有模板
taobao.logistics.address.search 查询卖家地址库
taobao.logistics.companies.get 查询物流公司信息
taobao.logistics.orders.detail.get 批量查询物流订单,返回详细信息
taobao.logistics.orders.get 批量查询物流订单
taobao.logistics.partners.get 查询支持起始地到目的地范围的物流公司
taobao.logistics.trace.search 物流流转信息查询
'''

from TopAPI.lib import *
import json

class areas():
	api='taobao.areas.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,format='json'):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']='id,type,name,parent_id,zip'
		url=getURL(d)
		return getRes(url)
	def parseData(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return j
	pass
class delivery_template():
	api='taobao.delivery.template.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,template_ids,user_nick='',session='',format='json'):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']='template_id,name,assumer,valuation,fee_list,\
		supports,created,modified'
		url=getURL(d)
		return getRes(url)
	def parseData(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return j
	pass
class delivery_templates():
	api='taobao.delivery.templates.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,session,format='json'):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']='template_id,name,assumer,valuation,fee_list,\
		supports,created,modified'
		url=getURL(d)
		return getRes(url)
	def parseData(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return j
	pass
class logistics_address():
	api='taobao.logistics.address.search'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,session,rdef='no_def',format='json'):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		url=getURL(d)
		return getRes(url)
	def parseData(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return j
	pass
class logistics_companies():
	api='taobao.logistics.companies.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,is_recommended='true',order_mode='offline'format='json'):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		url=getURL(d)
		return getRes(url)
	def parseData(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return j
	pass
class logistics_orders_detail():
	api='taobao.logistics.orders.detail.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,session,
		tid=None,buyer_nick=None,
		status=None,seller_confirm=None,
		receiver_name=None,start_created=None,
		end_created=None,freight_payer=None,
		type=None,page_no=None,page_size=None
		format='json'):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']='tid,order_code,is_quick_cod_order,seller_nick,buyer_nick,\
		delivery_start,delivery_end,out_sid,item_title,receiver_name,\
		receiver_phone,receiver_mobile,location,status,type,\
		freight_payer,seller_confirm,company_name,is_success,created,\
		modified'
		url=getURL(d)
		return getRes(url)
	def parseData(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return j
	pass
class logistics_orders():
	api='taobao.logistics.orders.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,session,
		tid=None,buyer_nick=None,
		status=None,seller_confirm=None,
		receiver_name=None,start_created=None,
		end_created=None,freight_payer=None,
		type=None,page_no=None,page_size=None
		format='json'):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']='tid,order_code,is_quick_cod_order,seller_nick,buyer_nick,\
		delivery_start,delivery_end,out_sid,item_title,receiver_name,\
		receiver_phone,receiver_mobile,location,status,type,\
		freight_payer,seller_confirm,company_name,is_success,created,\
		modified'
		url=getURL(d)
		return getRes(url)
	def parseData(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return j
	pass
class logistics_partners():
	api='taobao.logistics.partners.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,
		service_type=None,source_id=None,
		target_id=None,goods_value=None,
		is_need_carriage=None
		format='json'):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		url=getURL(d)
		return getRes(url)
	def parseData(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return j
	pass
class logistics_trace():
	api='taobao.logistics.trace.search'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,tid,seller_nick,format='json'):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		url=getURL(d)
		return getRes(url)
	def parseData(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return j
	pass

def main():
	pass
if __name__=='__main__':
	main()
	pass
